Ext.namespace('iOS.Button');

Ext.define('HomeButton', {
    extend: 'Button',
    
    statics : {
        ViewCls    : 'home-button',
        ScreenView : 'icon-screen',
        AppContent : 'app-content',
        TopBar     : 'top-bar'
    },
    
    _eventList : [
        ['enableIconAnim'],
        ['disableHome'],
        ['enableShakeIcon']
    ],
    
    enableIconAnim : function(){
        var that   = this,
            sttc   = this.self;
        this.getElCache().off($.support.click).on($.support.click, function(){
            var appCon      = iOS.ViewManager.getView(sttc.AppContent);
            if(!appCon.isIframe()){
                var appName = appCon.getCurAppName(),
                    app;
                appCon.getElCache().on('webkitTransitionEnd', function(){
                    var $this = $(this);
                    app       = $this.children().detach();
                    $this.off('webkitTransitionEnd');
                    iOS.BackStage.addApp(appName, app);
                })                
            }
            iOS.ViewManager.notify(sttc.ScreenView, 'iconIn');
            iOS.ViewManager.notify(sttc.AppContent, 'closeApp');
            iOS.ViewManager.notify(sttc.TopBar,     'initTopBar');
        })
    },
    
    enableShakeIcon : function(){
        var that = this,
            sttc = this.self;
        this.getElCache().off($.support.click).on($.support.click, function(){
            iOS.ViewManager.notify(sttc.ScreenView, 'stopShake');
            iOS.ViewManager.notify(sttc.ScreenView, 'disableDrag');
            iOS.ViewManager.notify(this,            'enableIconAnim');
        })
    },
    
    disableHome: function(){
        this.getElCache().off();
    }
});

iOS.Button.HomeButton = HomeButton;
